<?php

// +----------------------------------------------------------------------
// | author: admin
// +----------------------------------------------------------------------

namespace app\adminapi\lists\travel;


use app\adminapi\lists\BaseAdminDataLists;
use app\common\lists\ListsSearchInterface;
use app\common\lists\ListsSortInterface;
use app\common\model\travel\TravelAgency;

/**
 * TravelAgency列表
 * Class TravelAgencyLists
 * @package app\adminapi\liststravel
 */
class TravelAgencyLists extends BaseAdminDataLists implements ListsSearchInterface, ListsSortInterface
{

    /**
     * @notes 设置搜索条件
     * @return array
     * @author admin
     * @date 2025/04/23 18:23
     */
    public function setSearch(): array
    {
        return [
            '=' => ['status'],
            '%like%' => ['name', 'contact_name'],
        ];
    }

    /**
     * @notes  设置支持排序字段
     * @return array
     */
    public function setSortFields(): array
    {
        return ['create_time' => 'create_time', 'id' => 'id'];
    }

    /**
     * @notes  设置默认排序
     * @return array
     */
    public function setDefaultOrder(): array
    {
        return ['sort' => 'desc', 'id' => 'desc'];
    }


    /**
     * @notes 获取列表
     * @return array
     * @author admin
     * @date 2025/04/23 18:23
     */
    public function lists(): array
    {
        return TravelAgency::where($this->searchWhere)
            ->field(['id', 'name', 'licence', 'business_licence', 'contact_phone', 'contact_name', 'address', 'desc', 'travel_money', 'brokerage_percent', 'status','sort'])
            ->limit($this->limitOffset, $this->limitLength)
            ->order($this->sortOrder)
            ->select()
            ->toArray();
    }


    /**
     * @notes 获取数量
     * @return int
     * @author admin
     * @date 2025/04/23 18:23
     */
    public function count(): int
    {
        return TravelAgency::where($this->searchWhere)->count();
    }

}